home *** CD-ROM | disk | FTP | other *** search
- /* vsprintf.c --- p 483 */
- #include <stdio.h>
- #include <stdarg.h> /* ANSI C compatible */
- #include <conio.h>
- void error_handler(char *,...);
- char filename[80] = "COMMAND.COM";
- main()
- {
- int offset = 0x232A;
- /* Assume we are already in text mode */
- clrscr(); /* Clear screen */
- window (10, 10, 70, 15); /* Define text window*/
- textattr (YELLOW+(RED <<4)); /* Set background to red */
- clrscr(); /* clear out text window */
- /* Once a text window is defined all text positions are
- * relative to upper left corner of the window. Notice
- * that this can be used for pop_up menus. */
- gotoxy(1,1); /* Set text position */
- /* Call the error handler to print an error message.
- * First just a single line. Then a more detailed
- * message with more arguments. */
- error_handler("System error\n");
- error_handler("File %s at offset %x\n", filename, offset);
- }
- /*----------------------------*/
- /* error_handler: accepts variable number of arguments
- * and prints messages */
- void error_handler(char *my_format,...)
- {
- va_list arg_pointer;
- char buffer[80]; /* Buffer for text string */
- /* Use va_start macro to get to the start of the
- * variable number of arguments. This will alter the
- * pointer arg_pointer to point to the list of
- * variables to be printed. */
- va_start(arg_pointer, my_format);
- vsprintf(buffer, my_format, arg_pointer);
- /* Now display the message by calling cputs */
- cputs (buffer);
- cputsJ("\r");
- /* Use the va_end macro to reset the arg_pointer */
- va_end(arg_pointer);
- }